<?php
include("model/payments.php");
class paymentsController{
	
	function indexAction(){
		$smarty = $_SESSION['smarty'];
		
		$list_payments_box = $this->getListPaymentBox();
		$smarty->assign("list_payments_box",$list_payments_box);
		
		$content = $smarty->fetch("payments/payments.html");		
		$smarty->assign("content", $content);
		
		$smarty->display("homepage.html");
	}
	
	function getListPaymentBox(){
		$smarty 	= $_SESSION['smarty'];
		$payment_obj 	= new payments();
		$paymentList	= $payment_obj->getPaymentsList();		
		$smarty->assign("paymentList", $paymentList);
		$html 		= $smarty->fetch("payments/payments_list.html");
		return $html;
	}
		
	function insertAction(){
		$payments_obj = new payments();
		$data 		= array();
		$data['pay_method'] = $_REQUEST['pay_method'];
		$result = $payments_obj->insertAPayment($data);
		if ($result == 1)
			$msg = "insert successfully";
		else if ($result == -1)
			$msg = "duplicated!";
		else
			$msg = "insert failed.";
			
		$smarty = $_SESSION['smarty'];		
		$smarty->assign("msg", $msg);
		$content = $smarty->fetch("payments/payments_insertResult.html");		
		$smarty->assign("content", $content);		
		$smarty->display("homepage.html");
		
	}
	
	function inactiveAction(){
		$pay_id = $_REQUEST['args'];
		$payments_obj = new payments();
		$result = $payments_obj->inactivateAPayment($pay_id);
		if ($result == 1)
			$msg = "inactivate successfully";		
		else
			$msg = "inactivate failed.";
			
		$smarty = $_SESSION['smarty'];		
		
		
		$list_payments_box = $this->getListPaymentBox();
		$smarty->assign("list_payments_box",$list_payments_box);
		$smarty->assign("msg", $msg);
		
		$content = $smarty->fetch("payments/payments.html");		
		$smarty->assign("content", $content);		
		$smarty->display("homepage.html");
	}
	
	function activeAction(){
		$pay_id = $_REQUEST['args'];
		$payments_obj = new payments();
		$result = $payments_obj->activateAPayment($pay_id);
		if ($result == 1)
			$msg = "activate successfully";		
		else
			$msg = "activate failed.";
			
		$smarty = $_SESSION['smarty'];		
		
		$list_payments_box = $this->getListPaymentBox();
		$smarty->assign("list_payments_box",$list_payments_box);
		$smarty->assign("msg", $msg);
		
		$content = $smarty->fetch("payments/payments.html");		
		$smarty->assign("content", $content);		
		$smarty->display("homepage.html");
	}
	
	function insertFormAction(){
		$smarty = $_SESSION['smarty'];		
		
		$insertform_payments_box = $smarty->fetch("payments/payments_insert_form.html");
		$smarty->assign("insertform_payments_box",$insertform_payments_box);
		
		$content = $smarty->fetch("payments/payments.html");		
		$smarty->assign("content", $content);
		
		$smarty->display("homepage.html");
	}
	
	function editFormAction(){
		$pay_id 			= $_REQUEST['args'];
		$smarty 		= $_SESSION['smarty'];		
		
		$payments_obj 	= new payments();
		$current_data 		= array();
		$current_data 		= $payments_obj->getPaymentsInfo($pay_id);
		
		$smarty->assign("current_data", $current_data);
		
		$editform_payments_box = $smarty->fetch("payments/payments_edit_form.html");
		$smarty->assign("editform_payments_box",$editform_payments_box);
		
		$content = $smarty->fetch("payments/payments.html");		
		$smarty->assign("content", $content);
		
		$smarty->display("homepage.html");
		
	}
	
	function editAction(){
		$payments_obj = new payments();
		$data 		= array();
		$data['pay_method'] 	= $_REQUEST['pay_method'];
		$data['pay_id'] 		= $_REQUEST['pay_id'];
		
		$result = $payments_obj->editAPayment($data);
		
		if ($result == 1)
			$msg = "edit successfully";
		else if ($result == -1)
			$msg = "duplicated!";
		else
			$msg = "update failed.";
			
		$smarty = $_SESSION['smarty'];		
		$smarty->assign("msg", $msg);
		$content = $smarty->fetch("payments/payments_updateResult.html");		
		$smarty->assign("content", $content);		
		$smarty->display("homepage.html");
	}
}
?>